<?php
/**
 * Created by PhpStorm.
 * User: wjm
 * Date: 2017-04-21
 * Time: 下午 1:57
 */

namespace app\hongyanche\controller;

use think\Db;
class Mall
{
    public function __construct()
    {
        model('product') ->demand('mall');
    }
    //labels  获取标签
    public function labels(){
        $res = model('label')->rank('mall');
        return json($res);
    }
    //menu  获取菜单
    public function menu(){
        $filer['page'] = input('page');
        $filer['maxPerPage'] = input('maxPerPage');
        $filer['keywords'] = input('kyewords');
        $filer['select'] = input('labels');
        $res = model('product')->getList($filer);
        return json($res);
    }


    //获取购物车列表
    public function get_cartlist(){
        $filter['page'] = input('page');
        $filter['maxPerPage'] = input('maxPerPage');
        $filter['keywords'] = input('keywords');
        $filter['demand'] = 'mall';
        $res = model('cart')->getList($filter);
        return json($res);
    }
    //product_getlist 获取产品列表
    public function product_list(){
        $filer['page'] = input('page');
        $filer['maxPerPage'] = 15;
        $filer['keywords'] = input('keywords');
        $filer['select'] = input('labels');
        $res = model('mall')->getList($filer);
        return json($res);
    }
    //config_getlist  获取配置层列表
    public function config_create(){
        $data['labels'] = input('labels');
        $data['mall_id'] = input('mall_id');
        $data['confing_descripton'] = input('confing_descripton');
        $res = model('mall')->config_create($data);
        return json($res);
    }
    public function config_remove(){
        $config_id = input('config_id');
        $res = model('mall')->config_detail_remove($config_id);
        return json($res);
    }
    public function config_getList(){
        $config_template_id = input('config_template_id');
        $mall_id = input('mall_id');
        $res = model('mall')->config_list($config_template_id,$mall_id);
        return json($res);
    }
    //detail_getlist  获取型号列表
    public function detail_getlist(){
        $filer['page'] = input('page');
        $filer['maxPerPage'] = input('maxPerPage');
        $filer['select'] = input('mall_id');
        $res = model('product')->detail_getList($filer);
        return json($res);
    }


    //修改购物车数量
    public function modify()
    {
        $detail = input("deatil");
        $res = model('cart')->setNum($detail);
        return json($res);
    }
    //清空购物车
    public function remove()
    {
        $cart_id = input("cart_id");
        $res = model('cart')->remove($cart_id);
        return json($res);
    }
    //用户加入购物车
    public function add_cart(){
        $detail = input('detail');
        $res = model('cart')->add('mall',$detail);
        return json($res);
    }
    //用户生成订单
    public function order_create()
    {
        $address_id = input('address_id');
        $detail = input('detail');
        $content = input('content');
        if(!$content){
            $content = "";
        }
        $res = model('mall')->orderCreate($detail,$content,$address_id);
        return json($res);
    }
    //用户查询订单
    public function order_list()
    {
        $filter['page'] = input('page');
        $filter['maxPerPage'] = input('maxPerPage');
        $filter['keywords'] = input('keywords');
        $res = model('mall')->userOrderList($filter);
        return json($res);
    }
    //order_get_price 计算价格
    public function order_get_price(){
        $detail = input('detail');
        $card_code = input('card_code');
        $res = model('mall')->reckonPrice($detail,$card_code);
        return json($res);
    }
    
    //根据mall_id查询单个产品详细信息
    public function product_info(){
        $mall_id = input('mall_id');
        $res = model('mall')->getMallInfoById($mall_id,1);
        return json($res);
    }


    //用户收货地址详细列表
    public function address_list(){
        $res = model('mall')->address_list();
        return json($res);
    }
    //创建收货地址
    public function address_create(){
        $data = [
            'address_name'=>input('address_name'),
            'address_tel'=>input('address_tel'),
            'address_code'=>input('address_code'),
            'address'=>input('address'),
            'other'=>input('other'),
            'address_province'=>input('address_province'),
            'address_city'=>input('address_city'),
//            'address_district'=>input('district'),
            'address_landline'=>input('address_landline'),

        ];
        $res = model('mall')->address_create($data);
        return json($res);
    }
    /*//编辑收货地址
    public function address_modify(){
        $address = input('address_id');
        $key     = input('key');
        $content = input('content');
        $res = model('mall')->address_modify($address,$key,$content);
        return json($res);
    }*/
    //删除收货地址
    public function address_remove(){
        $address = input('address_id');
        $res = model('mall')->address_remove($address);
        return json($res);
    }
    //收货地址排序
    public function range(){
        $ranges  = input('ranges');
        $res = model('mall')->range($ranges);
        return json($res);
    }
    //设置默认收货地址
    public function address_default(){
        $address_id= input('address_id');
        $res = model('mall')->address_default($address_id);
        return json($res);
    }

    //左侧导航栏
    public function suggest(){
        $res = model('mall')->suggest();
        return json($res);
    }

}